// TrainDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ConfigGUI.h"
#include "ConfigGUIDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTrainDlg dialog

IMPLEMENT_DYNAMIC(CTrainDlg, CDialog)

CTrainDlg::CTrainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTrainDlg::IDD, pParent), m_psTrain(NULL), m_pConfig(NULL)
{
	//{{AFX_DATA_INIT(CTrainDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CTrainDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTrainDlg)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTrainDlg, CDialog)
	//{{AFX_MSG_MAP(CTrainDlg)
	ON_WM_CLOSE()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrainDlg message handlers

BOOL CTrainDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_psTrain = new CTrainPropertySheet(_T(""), this);
	m_psTrain->SetContainer(this);

	// create a modeless property page
	if (!m_psTrain->Create(this,
			DS_CONTEXTHELP | DS_SETFONT | WS_CHILD | WS_VISIBLE))
	{
		m_psTrain->DestroyWindow();
		return FALSE;
	}

	/* must add following line to avoid a deadlock of system */
	m_psTrain->ModifyStyleEx(0, WS_EX_CONTROLPARENT);

	m_psTrain->SetWindowPos(NULL, 0, 0, 0, 0,
			SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTrainDlg::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	if (NULL != m_psTrain) { delete m_psTrain; m_psTrain = NULL; }
	CDialog::PostNcDestroy();
}

void CTrainDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnClose();
	DestroyWindow();
	m_pConfig->ResetBtnTrainSub();
}

void CTrainDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if (VK_ESCAPE == nChar)
	{
		SendMessage(WM_CLOSE, 0, 0L);
	}

	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
